import org.junit.Test;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author: mazhongqing
 * @Date: 2020/10/19 20:15
 */
public class Sync_wait_notify {
    Thread t1,t2;

    @Test
    public void demo(){
        final Object o = new Object();
        char[] aI = "123456".toCharArray();
        char[] aC = "ABCDEF".toCharArray();

        t1 = new Thread(()->{
            synchronized (o) {
                for (char c : aI) {
                    System.out.print(c);
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                o.notify();
            }
        });

        t2 = new Thread(()->{
            synchronized (o) {
                for (char c : aC) {
                    System.out.print(c);
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                o.notify();
            }
        });

        t1.start();
        t2.start();
    }
}
